#include <iostream>
#include <fstream>
#include <vector>
#include <chrono>

using namespace std;
using namespace std::chrono;

void bubble_sort(vector<int>& a) {
    int n = a.size();
    for (int i = 0; i < n; i++) {
        bool swapped = false;
        for (int j = 0; j < n - i - 1; j++) {
            if (a[j] > a[j + 1]) {
                swap(a[j], a[j + 1]);
                swapped = true;
            }
        }
        if (!swapped) {
            break;
        }
    }
}

int main() {
    vector<string> file_names = {"m1_sorted.txt", "m2_reverse.txt", "m3_shuffle.txt"};

    for (const string& file : file_names) {
        ifstream input(file);
        vector<int> b;
        int num;
        while (input >> num) {
            b.push_back(num);
        }
        input.close();
        
        auto start_time = high_resolution_clock::now();
        bubble_sort(b);
        auto end_time = high_resolution_clock::now();
        auto duration = duration_cast<milliseconds>(end_time - start_time);
        string file_name = file.substr(0, file.find("."));
        cout << file_name << "  " << duration.count() << " milliseconds" << endl;
    }

    return 0;
}